/*
 * @Author: hexudong 1264275442@qq.com
 * @Date: 2023-04-11 15:49:23
 * @LastEditors: hexudong 1264275442@qq.com
 * @LastEditTime: 2023-04-25 14:30:28
 * @FilePath: /worker_supervision_oa/src/components/BorrowDetail/base.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import React, { useState, useEffect } from 'react';
import { Card, Descriptions, Button, Divider, message } from 'antd';
import RenderMoreFile from '@/components/FileMoreRender';
import ProcessModal from './processModal';
import SendModal from './sendModal';
import ReturnModal from './returnModal';
import { accDiv, changeTimeFormat, formatDateIOS } from '@/utils/utils';
import { repayLoanApply } from '@/services/public';
interface BaseProps {
  type: string;
  query: any;
  detailMessage: any;
  status: number;
  onSubmit: () => void;
}
const Base: React.FC<BaseProps> = ({ type, query, detailMessage, status, onSubmit }) => {
  const [showModal, setShowModal] = useState<boolean>(false);
  const [showSendModal, setShowSendModal] = useState<boolean>(false);
  const [showReturnModal, setShowReturnModal] = useState<boolean>(false);
  const [canCommit, setCanCommit] = useState<boolean>(false);
  const sureModal = () => {
    if (status == 1 && type != 'construction') {
      setShowModal(true);
    } else if (type == 'bank' && status == 2) {
      setShowSendModal(true);
    } else if (type == 'bank' && status == 3) {
      setShowReturnModal(true);
    }
  };
  const toPay = async () => {
    const res = await repayLoanApply({ id: query.id });

    if (res && res.success) {
      message.success('申请成功，等待银行审核确认还款');
      setCanCommit(true);
      onSubmit();
    }
  };

  useEffect(() => {
    // getDetail(type)
    if (query.repayLoanStatus == 1) {
      setCanCommit(true);
    } else {
      setCanCommit(false);
    }

    sureModal();
  }, []);
  return (
    <>
      <Divider />
      <Descriptions size="small" column={1} labelStyle={{ fontWeight: 'bold', width: '120px' }}>
        <Descriptions.Item label="贷款状态">{detailMessage.loanStatusText}</Descriptions.Item>
        {detailMessage.loanStatus > 5 && (
          <Descriptions.Item label="还款状态">
            {detailMessage.repayLoanStatus == 0
              ? '未还款'
              : detailMessage.repayLoanStatus == 1
                ? '申请还款中'
                : detailMessage.repayLoanStatus == 2
                  ? '还款成功'
                  : '还款失败'}
          </Descriptions.Item>
        )}
        <Descriptions.Item label="贷款金额(元)">
          {detailMessage.amount ? accDiv(detailMessage.amount || 0, 100) : '-'}
        </Descriptions.Item>
        <Descriptions.Item label="贷款期限">{detailMessage.timeLimit}</Descriptions.Item>
        <Descriptions.Item label="申请时间">
          {changeTimeFormat(detailMessage.gmtCreate)}
        </Descriptions.Item>
        <Descriptions.Item label="贷款人">{detailMessage.applyName}</Descriptions.Item>
        <Descriptions.Item label="贷款人手机号">{detailMessage.phone}</Descriptions.Item>
        {/* {
                        type == 'bank' && (
                            <Descriptions.Item label="身份证照片(人像)">
                                <RenderMoreFile
                                    title="资料一"
                                    fielUrl="https://ossmediutestdaily.goodrs.cn/marginAccount/f172733d0a887f93ddcac36e63e741ad.pdf?Expires=1679433814&OSSAccessKeyId=LTAI4GEK55XqzSuGXk9dnoVE&Signature=bhnqZWDmr6aFTbPuBXM7ozo2iM4%3D"
                                />
                            </Descriptions.Item>
                        )
                    }
                    {
                        type == 'bank' && (
                            <Descriptions.Item label="身份证照片(国徽)">
                                <RenderMoreFile
                                    title="资料一"
                                    fielUrl="https://ossmediutestdaily.goodrs.cn/marginAccount/f172733d0a887f93ddcac36e63e741ad.pdf?Expires=1679433814&OSSAccessKeyId=LTAI4GEK55XqzSuGXk9dnoVE&Signature=bhnqZWDmr6aFTbPuBXM7ozo2iM4%3D"
                                />
                            </Descriptions.Item>
                        )
                    } */}
        <Descriptions.Item label="资料" span={2}>
          <Descriptions layout="vertical">
            {detailMessage.borrowerFilesUrl && (
              <Descriptions.Item label="借款人资料">
                <RenderMoreFile title="借款人资料" fielUrl={detailMessage.borrowerFilesUrl} />
              </Descriptions.Item>
            )}
            {detailMessage.loanProjectFilesUrl && (
              <Descriptions.Item label="借款项目资料">
                <RenderMoreFile title="借款项目资料" fielUrl={detailMessage.loanProjectFilesUrl} />
              </Descriptions.Item>
            )}
            {detailMessage.applyFilesUrl && (
              <Descriptions.Item label="其他资料">
                <RenderMoreFile title="其他资料" fielUrl={detailMessage.applyFilesUrl} />
              </Descriptions.Item>
            )}
            {detailMessage.loanVoucherFileUrl && (
              <Descriptions.Item label="放贷凭证">
                <RenderMoreFile title="放贷凭证" fielUrl={detailMessage.loanVoucherFileUrl} />
              </Descriptions.Item>
            )}
          </Descriptions>
          {/* {
                            detailMessage.borrowerFilesUrl && (
                                <RenderMoreFile
                                    title="借款人资料"
                                    fielUrl={detailMessage.borrowerFilesUrl}
                                />
                            )
                        }
                        {
                            detailMessage.loanProjectFilesUrl && (
                                <RenderMoreFile
                                    title="借款项目资料"
                                    fielUrl={detailMessage.loanProjectFilesUrl}
                                />
                            )
                        }
                        {
                            detailMessage.applyFilesUrl && (
                                <RenderMoreFile
                                    title="申请资料"
                                    fielUrl={detailMessage.applyFilesUrl}
                                />
                            )
                        }
                        {
                            detailMessage.loanVoucherFile && (
                                <RenderMoreFile
                                    title="放贷凭证"
                                    fielUrl={detailMessage.loanVoucherFile}
                                />
                            )
                        } */}
        </Descriptions.Item>
      </Descriptions>
      {/* <Divider orientation="left" plain dashed >审核信息</Divider> */}
      <Card title="审核信息" style={{ marginTop: '20px' }}>
        <Descriptions size="small" column={2} labelStyle={{ fontWeight: 'bold', width: '108px' }}>
          <Descriptions.Item label="平台审核意见">
            {detailMessage.sjbCheckStatus == 0
              ? '待审核'
              : detailMessage.sjbCheckStatus == 1
                ? '审核成功'
                : detailMessage.sjbCheckStatus == 2
                  ? '审核拒绝'
                  : '待审核'}
          </Descriptions.Item>
          <Descriptions.Item label="平台审核备注">
            {detailMessage.sjbCheckRemark ? detailMessage.sjbCheckRemark : '-'}
          </Descriptions.Item>
          <Descriptions.Item label="平台审核资料">
            <RenderMoreFile title="平台审核资料" fielUrl={detailMessage.sjbCheckFileUrl} />
          </Descriptions.Item>
        </Descriptions>
        {detailMessage.sjbCheckStatus == 1 && detailMessage.thirdPlatformId && (
          <span>
            <Divider orientation="left" plain dashed />
            <Descriptions
              size="small"
              column={2}
              labelStyle={{ fontWeight: 'bold', width: '130px' }}
            >
              <Descriptions.Item label="担保公司">
                {detailMessage.thirdPlatformName}
              </Descriptions.Item>
              <Descriptions.Item label="担保公司审核意见">
                {detailMessage.thirdPlatformCheckStatus == 0
                  ? '待审核'
                  : detailMessage.thirdPlatformCheckStatus == 1
                    ? '审核成功'
                    : detailMessage.thirdPlatformCheckStatus == 2
                      ? '审核拒绝'
                      : '待审核'}
              </Descriptions.Item>
              <Descriptions.Item label="担保公司审核备注">
                {detailMessage.thirdPlatformCheckRemark
                  ? detailMessage.thirdPlatformCheckRemark
                  : '-'}
              </Descriptions.Item>
              {/* <Descriptions.Item label=""></Descriptions.Item> */}
              {detailMessage.thirdPlatformCheckFileUrl && (
                <Descriptions.Item label="担保公司审核资料" span={2}>
                  <RenderMoreFile
                    title="担保公司审核资料"
                    fielUrl={detailMessage.thirdPlatformCheckFileUrl}
                  />
                </Descriptions.Item>
              )}
            </Descriptions>
          </span>
        )}
        {(detailMessage.thirdPlatformCheckStatus == 1 ||
          (detailMessage.sjbCheckStatus == 1 && !detailMessage.thirdPlatformId)) && (
            <span>
              <Divider orientation="left" plain dashed />
              <Descriptions
                size="small"
                column={2}
                labelStyle={{ fontWeight: 'bold', width: '108px' }}
              >
                <Descriptions.Item label="银行审核意见">
                  {detailMessage.bankCheckStatus == 0
                    ? '待审核'
                    : detailMessage.bankCheckStatus == 1
                      ? '审核成功'
                      : detailMessage.bankCheckStatus == 2
                        ? '审核拒绝'
                        : '待审核'}
                </Descriptions.Item>
                <Descriptions.Item label="银行审核备注">
                  {detailMessage.bankCheckRemark ? detailMessage.bankCheckRemark : '-'}
                </Descriptions.Item>
                <Descriptions.Item label="银行审核贷款金额(元)">
                  {(detailMessage.bankCheckAmount || detailMessage.bankCheckAmount == 0) ? accDiv(detailMessage.bankCheckAmount || 0, 100) : '-'}
                </Descriptions.Item>
                <Descriptions.Item label="银行审核贷款期限（月）">
                  {detailMessage.bankCheckTimeLimit ? detailMessage.bankCheckTimeLimit : '-'}
                </Descriptions.Item>
                {detailMessage.bankCheckFileUrl && (
                  <Descriptions.Item label="银行审核资料">
                    <RenderMoreFile title="资料一" fielUrl={detailMessage.bankCheckFileUrl} />
                  </Descriptions.Item>
                )}

              </Descriptions>
            </span>
          )}
        {detailMessage.bankCheckStatus == 1 && (
          <span>
            <Divider orientation="left" plain dashed />
            <Descriptions
              size="small"
              column={1}
              labelStyle={{ fontWeight: 'bold', width: '108px' }}
            >
              <Descriptions.Item label="劳监审核备注">
                {detailMessage.ljCheckRemark ? detailMessage.ljCheckRemark : '-'}
              </Descriptions.Item>
              <Descriptions.Item label="劳监意见书">
                <RenderMoreFile title="资料一" fielUrl={detailMessage.ljCheckFileUrl} />
              </Descriptions.Item>
            </Descriptions>
          </span>
        )}
        {detailMessage.loanStatus >= 4 && detailMessage.loanStatus != 5 && (
          <span>
            <Divider orientation="left" plain dashed />
            <Descriptions
              size="small"
              column={2}
              labelStyle={{ fontWeight: 'bold', width: '108px' }}
            >
              <Descriptions.Item label="银行发放状态">
                {detailMessage.bankSendStatus == 0
                  ? '待发放'
                  : detailMessage.bankSendStatus == 1
                    ? '发放成功'
                    : detailMessage.bankSendStatus == 2
                      ? '发放失败'
                      : '待发放'}
              </Descriptions.Item>
              <Descriptions.Item label="贷款开始时间">
                {formatDateIOS(detailMessage.startTime)}
              </Descriptions.Item>
              <Descriptions.Item label="应还款日期">
                {formatDateIOS(detailMessage.endTime)}
              </Descriptions.Item>
              {/* <Descriptions.Item label=""></Descriptions.Item> */}
              {detailMessage.loanVoucherFileUrl && (
                <Descriptions.Item label="银行发放凭证" span={2}>
                  <RenderMoreFile title="资料一" fielUrl={detailMessage.loanVoucherFileUrl} />
                </Descriptions.Item>
              )}
              {detailMessage.bankSendRemark && (
                <Descriptions.Item label="银行发放备注">
                  {detailMessage.bankSendRemark ? detailMessage.bankSendRemark : '-'}
                </Descriptions.Item>
              )}
            </Descriptions>
          </span>
        )}
      </Card>
      {detailMessage.loanStatus == 6 && (
        <Card title="还款信息" style={{ marginTop: '20px' }}>
          {detailMessage.repayLoanStatus == 1 || detailMessage.repayLoanStatus == 2 ? (
            <Descriptions size="small" column={1} labelStyle={{ fontWeight: 'bold' }}>
              <Descriptions.Item label="还款凭证">
                <RenderMoreFile title="还款凭证" fielUrl={detailMessage.repayFileUrl} />
              </Descriptions.Item>
              <Descriptions.Item label="银行审核意见">
                {detailMessage.repayBankCheckStatus == 0
                  ? '待审核'
                  : detailMessage.repayBankCheckStatus == 1
                    ? '审核成功'
                    : '-'}
              </Descriptions.Item>
              {detailMessage.repayBankCheckRemark && (
                <Descriptions.Item label="还款审核备注">
                  {detailMessage.repayBankCheckRemark ? detailMessage.repayBankCheckRemark : '-'}
                </Descriptions.Item>
              )}
            </Descriptions>
          ) : (
            type == 'construction' && (
              <>
                <Descriptions size="small" column={1} labelStyle={{ fontWeight: 'bold' }}>
                  <Descriptions.Item label="银行审核确认的金额(元)">
                    {(detailMessage.bankCheckAmount || detailMessage.bankCheckAmount == 0) ? accDiv(detailMessage.bankCheckAmount || 0, 100) : '-'}
                  </Descriptions.Item>
                </Descriptions>
                <Button
                  type="primary"
                  disabled={canCommit}
                  onClick={() => {
                    toPay();
                  }}
                >
                  申请还款
                </Button>
              </>
            )
          )}
        </Card>
      )}

      {showModal && (
        <Card title="申请贷款审核" style={{ marginTop: '20px' }}>
          <ProcessModal detailMessage={detailMessage} type={type} onSubmit={onSubmit} />
        </Card>
      )}
      {type == 'bank' && showSendModal && (
        <Card title="上传贷款材料" style={{ marginTop: '20px' }}>
          <SendModal detailMessage={detailMessage} onSubmit={onSubmit} />
        </Card>
      )}
      {type == 'bank' && showReturnModal && (
        <Card title="还款审核" style={{ marginTop: '20px' }}>
          <ReturnModal detailMessage={detailMessage} onSubmit={onSubmit} />
        </Card>
      )}
    </>
  );
};
export default Base;
